<?php
require('common.inc.php');
// if(empty($_SERVER['HTTP_REFERER'])) exit;

$act = trim($_GET['act']);
switch ($act) {
    case 'getuserid':
        getuserid();
        break;
    case 'getusername':
        getusername();
        break;
    case 'chkuser':
        chkuser();
        break;
    case 'tiben':
        tiben();
        break;
    case 'chktu':
        chktu();
        break;
    case 'getaddress':
        getaddress();
        break;
    case 'getaddress_btc':
        getaddress_btc();
        break;
    case 'getaddress_ltc':
        getaddress_ltc();
        break;
    case 'deleqd':
        deleqd();
        break;
    case 'checkphone':
        checkphone();
        break;
    case 'changephone':
        changephone();
        break;
    case 'chkmobile':
        chkmobile();
        break;
    case 'chkmobile2':
        chkmobile2();
        break;
    case 'help_detail':
        help_detail();
        break;
    case 'give_help_detail':
        give_help_detail();
        break;
    case 'give_help_dzorders':
        give_help_dzorders();
        break;
    case 'checkvalicode':
        checkvalicode();
        break;
    case 'choice_lange':
        choice_lange();
    case 'chkbank':
        chkbank();
        break;
    case 'chuchang':
        chuchang();
        break;
    case 'cunqian':
        lsf_cunqian();
        break;
    case 'userCashCoin':
        lsf_toUserCashCoin();
        break;
    case 'get_meal':
        get_meal();
        break;
}

function get_meal(){
    global $db;
    $id = $_POST['id'];
    $sql = 'select * from ld_set_meal where id = '.$id;
    $db->query($sql,2);
    die(json_encode($db->rs));
} 

function lsf_toUserCashCoin()
{
    global $db, $GLOBALARR, $member, $r;
    $_userid = $_SESSION['userid'];
    $r = $member->getuserinfo($_userid);
    $num = intval(checkstr($_GET['num']));
    $toUname= (checkstr($_GET['toUname']));

    $cashPurse=doubleval($r["cash_purse"]);

    if ($_userid <= 0) {
        echo json_encode(array('tips' => "请先登录！", 'status' => 0));
        return;
    }

    if ($cashPurse<$num) {
        echo json_encode(array('tips' => "您的VIC数量不够！", 'status' => 0));
        return;
    }

    try {
        $db->begintransaction();         //事物开始

        $db->sitedbexec("update ld_user_account set cash_purse=cash_purse-".$num." where uname='".$r['uname']."'");
        $db->sitedbexec("update ld_user_account set cash_purse=cash_purse+".$num." where uname='".$toUname."'");

        $arr["fromUserID"]=$_userid;
        $arr["fromUser"]=$r["uname"];
        $arr["toUser"]=$toUname;
        $arr["coinNum"]=$num;
        $arr["insertTime"]=time();
        $sql = getinsertsql($arr, 'ld_toUserCoin');
        $db->query($sql, 5);
        $db->committransaction();    //关闭自动提交
    } catch (PDOException $e) {
        $db->rollbacktransaction();
        a_bck("error".$e);
    }
    echo json_encode(array('tips' => "转入成功", 'status' => 1));
    return;
}

//提供帮助（f0510）
//  /ajax.php?act=cunqian&jine=20&pwd=123456&xf_type=1&tctype=A
function lsf_cunqian()
{
    global $db, $GLOBALARR, $member, $r;
    $_userid = $_SESSION['userid'];
    $r = $member->getuserinfo($_userid);
    $xf_type = intval(checkstr($_GET['xf_type']));
    $tctype = (checkstr($_GET['tctype']));
    $id = (checkstr($_GET['dataid']));

    if ($_userid <= 0) {
        echo json_encode(array('tips' => "请先登录！", 'status' => 0));
        return;
    }
    if (empty($tctype)) {
        echo json_encode(array('tips' => "请选择套餐！", 'status' => 0));
        return;
    }
    //$taocan = array("A", "B", "C", "D", "E");
//    $taocanday = array("A" => 0, "B" => 15, "C" => 30, "D" => 60, "E" => 90);

    //读取后台配置参数
    $db->query("select *  from ld_set_meal  WHERE  id = ".$id,2);
    $day = $db->rs;
/*
    $taocanday['A']  = $day['setting_value'];
    $taocanday['B']  = $day['setting_value'];
    $taocanday['C']  = $day['setting_value'];
    $taocanday['D']  = $day['setting_value'];
    $taocanday['E']  = $day['setting_value'];
*/
    if(empty($day)){
    	echo json_encode(array('tips' => "套餐选择不正确！", 'status' => 0));
        return;
    }
    $tday = $taocanday[$tctype];

    if ($xf_type != 1 && $xf_type != 2 && $xf_type != 3) {
        echo json_encode(array('tips' => "请选择锁仓方式！", 'status' => 0));
        return;
    }
    //if (!check_ipop_limit("cunqian", 13)) {
        // echo json_encode(array('tips'=>'请不要频繁提交','status'=>0));
        // return;
    //}
    if ($r['is_freezed'] == 1) {
        echo json_encode(array('tips' => '此账号已被冻结', 'status' => 0));
        return;
    }
   // print(json_encode($r));die;


    $pwd = checkstr(trim($_GET['pwd']));
    $jine = (checkstr(trim($_GET['jine'])));//获取金额

    //$ids = checkstr($_GET['ids']);
    //$nums = checkstr($_GET['nums']);
    $pwd = md5(md5($_GET['pwd'] . SITEENCRYPT));//获取加密后的密码 其中SITEENCRYPT为加密常量；

    if (!is_numeric($jine)) {
        echo json_encode(array('tips' => "您输入的数量不是一个数字", 'status' => 0));
        return;
    }
    if (empty($pwd)) {
        echo json_encode(array('tips' => "请输入密码", 'status' => 0));
        return;
    }

    if ($r['rgpwd2'] != $pwd) {
        echo json_encode(array('tips' => "您输入的密码不正确", 'status' => 0));
        return;
    }
    if(!($jine >= $day['min'] && $jine <= $day['max'])){
    	echo json_encode(array('tips' => "您输入的数量与套餐额度不匹配", 'status' => 0));
        return;
    }
    if ($jine < 20) {
        echo json_encode(array('tips' => "锁仓金额不得小于20！", 'status' => 0));
        return;
    }
    //消费方式
    /**************
     ****1本金
     ****2利息
     ****3动态
     ****4本金+利息+动态
     ***************/
    if ($xf_type == 1 && $jine > $r['cash_purse']) {
        echo json_encode(array('tips' => "你的VIC余额不足！", 'status' => 0));
        return;
    }
    if ($xf_type == 2 && $jine > $r['lixi_crash']) {
        echo json_encode(array('tips' => "你的锁仓收益余额不足！", 'status' => 0));
        return;
    }
    if ($xf_type == 3 && $jine > $r['keyong_ldprize']) {
        echo json_encode(array('tips' => "你的团队收益余额不足！", 'status' => 0));
        return;
    }
    /*
    if ($xf_type == 4 && $jine > $r['keyong_ldprize'] + $r['cash_purse'] + $r['lixi_crash']) {
        echo json_encode(array('tips' => "你的可用余额不足！", 'status' => 0));
        return;
    }*/
    $param['uid'] = $r['id'];
    $param['nums'] = $jine;
    $param['type'] = $xf_type;
    $param['pid'] = $day['id'];
    $param['days'] = $day['days'];
    if(add_lock_data($param)){
	    record_log("添加锁仓", 0);
	    echo json_encode(array('tips' => "锁仓成功", 'status' => 1));
	    return;    	
    }else{
    	a_bck("error");
    }

}

function add_lock_data($param){
	global $db;
	$db->begintransaction();
	$time = time();
	$start_date = strtotime(date('Y-m-d',$time+24*60*60));
	$end_date = $start_date + (24*60*60*$param['days']);
	$tag = true;
	$insert_sql = "insert into ld_lock_log values(0,".$param['uid'].",".$param['nums'].",0,".$time.",".$param['type'].",".$start_date.",".$end_date.",".$param['pid'].",0)";
	$db->sitedbexec($insert_sql);
	$get_sql = "select * from ld_lock_log order by id desc limit 1";
	$db->query($get_sql,2);
	$rs = $db->rs;
	if($rs['uid'] == $param['uid'] && $rs['nums'] == $param['nums'] && $rs['status'] == 0 && $rs['add_time']==$time){
		$tag = $tag && true;
	}else{
		$tag = $tag && false;
	}
	$get_coin_sql = "select * from ld_user_account where id = ".$param['uid'];
	$db->query($get_coin_sql,2);

	$rs_coin = $db->rs;
	if(empty($rs_coin)){
		$tag = $tag && false;
	}
	switch ($param['type']) {
		case 1:
			$update_sql1 = "update ld_user_account set cash_purse = ".$rs_coin['cash_purse']." - ".$param['nums'].",freeze_benjin = ".$rs_coin['freeze_benjin']." + ".$param['nums']." where id = ".$param['uid'];
			$db->sitedbexec($update_sql1);
			$get_coin_sql = "select * from ld_user_account where id = ".$param['uid'];
			$db->query($get_coin_sql,2);
			$up_data = $db->rs;
			if((floatval($up_data['cash_purse']) == $rs_coin['cash_purse']- $param['nums']) && ($rs_coin['freeze_benjin'] + $param['nums'] == floatval($up_data['freeze_benjin']))){
				$tag = $tag && true;
			}else{
				$tag = $tag && false;
			}
			break;
		case 2:
			$update_sql1 = "update ld_user_account set lixi_crash = ".$rs_coin['lixi_crash']." - ".$param['nums'].",freeze_lixi = ".$rs_coin['freeze_lixi']." + ".$param['nums']." where id = ".$param['uid'];
			$db->sitedbexec($update_sql1);
			$get_coin_sql = "select * from ld_user_account where id = ".$param['uid'];
			$db->query($get_coin_sql,2);
			$up_data = $db->rs;
			if((floatval($up_data['lixi_crash']) == $rs_coin['lixi_crash']- $param['nums']) && ($rs_coin['freeze_lixi'] + $param['nums'] == floatval($up_data['freeze_lixi']))){
				$tag = $tag && true;
			}else{
				$tag = $tag && false;
			}
			break;
		case 3:
			$update_sql1 = "update ld_user_account set keyong_ldprize = ".$rs_coin['keyong_ldprize']." - ".$param['nums'].",freeze_ldj = ".$rs_coin['freeze_ldj']." + ".$param['nums']." where id = ".$param['uid'];
			$db->sitedbexec($update_sql1);
			$get_coin_sql = "select * from ld_user_account where id = ".$param['uid'];
			$db->query($get_coin_sql,2);
			$up_data = $db->rs;
			if((floatval($up_data['keyong_ldprize']) == $rs_coin['keyong_ldprize']- $param['nums']) && ($rs_coin['freeze_ldj'] + $param['nums'] == floatval($up_data['freeze_ldj']))){
				$tag = $tag && true;
			}else{
				$tag = $tag && false;
			}
			break;
		default:
			$tag = $tag && false;
			break;
	}
	if($tag){
		$db->committransaction();
		return true;
	}else{
		$db->rollbacktransaction();
		return false;
	}
}


//待修改
function get_fenxiao_data(){
	    $ci = 1;
    try {
        $db->begintransaction();         //事物开始
        $rt = fun_insertTime();

        $arr["uid"] = $r['id'];
        $arr["uname"] = $r['uname'];
        $arr["give_help_time"] = time();
        $arr["amount"] = $jine;
        $arr["give_help_no"] = $r['uname'] . date("YmdHis");
        $arr["ghelp_ulevel"] = $r["user_level"];
        $arr["xf_type"] = $xf_type;
        $arr["tctype"] = $tctype;
        $arr["tcdays"] = $tday;

        //写入提供帮助表
        $sql = getinsertsql($arr, 'ld_give_help', "amount");
        $db->query($sql, 5);
        $arr["id"] = $db->fval;/*取出第一列的值，也就是提供帮助表的ID值*/

        if ($xf_type == 1) {
            writeaccount(array($_userid, "1", 0, time(), 8, $jine, '选择' . $tctype . '套餐，编号' . $arr["give_help_no"]));
            //锁仓冻结加
            writeaccount(array($_userid, "0", 23, time(), 231, $jine, '选择' . $tctype . '套餐增加锁仓冻结金，编号' . $arr["give_help_no"]));
        }
        if ($xf_type == 2) {
            writeaccount(array($_userid, "1", 11, time(), 110, $jine, '选择' . $tctype . '套餐，编号' . $arr["give_help_no"]));
            //锁仓冻结加
            writeaccount(array($_userid, "0", 17, time(), 171, $jine, '选择' . $tctype . '套餐增加锁仓冻结利息，编号' . $arr["give_help_no"]));
        }
        if ($xf_type == 3) {
            writeaccount(array($_userid, "1", 9, time(), 90, $jine, '选择' . $tctype . '套餐，编号' . $arr["give_help_no"]));
            //锁仓冻结加
            writeaccount(array($_userid, "0", 18, time(), 181, $jine, '选择' . $tctype . '套餐增加锁仓冻结动态奖，编号' . $arr["give_help_no"]));
        }


        //解冻父级们的动态资产
        $db->query("select id from ld_give_help WHERE uname='" . $r['uname'] . "' and id<>{$arr['id']} and dtjd <> 1", 2);
        $hpid = $db->rs['id'];
        if ($xf_type == 2 && $hpid != NULL) {
            $fatherarr = array_reverse(explode(',', rtrim(trim($r['parents_ids'], ','), ',')));
            foreach ($fatherarr as $k => $v) { //给父级解冻相应的动态奖
                if ($k == 30) {
                    break;
                }
                if ($k > 3) {
                    $bili = $GLOBALARR['jjtjj'][3] * 0.01;
                } else {
                    $bili = $GLOBALARR['jjtjj'][$k] * 0.01;
                }
                $keyong = $jine * $bili; //解冻金额
                $fsql = "select cash_ldprize from ld_user_account WHERE id={$v}";
                $db->query($fsql, 2);
                $finfo = $db->rs;

                if ($finfo['cash_ldprize'] > $keyong) {
                    $sql = " keyong_ldprize = keyong_ldprize + {$keyong},cash_ldprize = cash_ldprize - {$keyong}";
                } elseif ($finfo['cash_ldprize'] <= $keyong) {
                    $keyong_ldprize = $finfo['cash_ldprize'];
                    $sql = " keyong_ldprize = keyong_ldprize + {$keyong_ldprize},cash_ldprize = 0";
                }
                $db->sitedbexec("update ld_user_account set " . $sql . " where id={$v}");
            }
            $db->sitedbexec("update ld_give_help set dtjd=1 where id={$hpid}");
        }
        /***取消
         * if($xf_type==4){
         * if($jine<=$r['cash_purse']){
         * writeaccount(array($_userid,"1",0,time(),8,$jine,'选择'.$tctype.'套餐，编号'.$arr["give_help_no"]));
         * }elseif($jine<=$r['lixi_crash']){
         * writeaccount(array($_userid,"1",11,time(),110,$jine,'选择'.$tctype.'套餐，编号'.$arr["give_help_no"]));
         * }elseif($jine<=$r['cash_ldprize']){
         * writeaccount(array($_userid,"1",9,time(),90,$jine,'选择'.$tctype.'套餐，编号'.$arr["give_help_no"]));
         * }else{
         * $yub=$jine-$r['cash_purse'];
         * writeaccount(array($_userid,"1",0,time(),8,$r['cash_purse'],'选择'.$tctype.'套餐，编号'.$arr["give_help_no"]));
         * if($yub>0){
         * //继续使用利息
         * if($yub>$r['lixi_crash']){
         * writeaccount(array($_userid,"1",11,time(),110,$r['lixi_crash'],'选择'.$tctype.'套餐，编号'.$arr["give_help_no"]));
         * $yud=$yub-$r['lixi_crash'];
         * writeaccount(array($_userid,"1",9,time(),90,$yud,'选择'.$tctype.'套餐，编号'.$arr["give_help_no"]));
         * }else{
         * writeaccount(array($_userid,"1",11,time(),110,$yub,'选择'.$tctype.'套餐，编号'.$arr["give_help_no"]));
         * }
         * }
         * }
         * }
         ****/
        //锁仓冻结加
        if ($tctype != 'A') {
            grant($jine, $arr["id"]);
        }

        //发放推荐人所得币
        if ( !empty($r['introducer_id'])){
            addRecommodReward($jine,$r['introducer_id']);
        }

        $db->committransaction();    //关闭自动提交
    } catch (PDOException $e) {
        $db->rollbacktransaction();
        a_bck("error");
    }
}

function lsf_cunqian_error()
{
    echo json_encode(array('tips' => "当前系统比较繁忙，请稍后重新提交！", 'status' => 0));
    return;
}

function chkbank()
{
    global $member;
    $bankno = checkstr($_GET['bankno']);
    $rs = $member->get_bank($bankno);
    if (empty($rs)) {
        echo json_encode(array('tips' => 'ok'));
    } else {
        echo json_encode(array('tips' => '此账号已被使用'));
    }
    exit;
}

function chkmobile()
{
    global $member;
    $value = checkstr($_GET['mobile']);
    $rs = $member->mobile_exists($value);
    if (!empty($rs)) {
        echo json_encode(array('tips' => "手机号码已经被使用"));
        exit;
    } else {
        echo json_encode(array('tips' => "手机号可以使用"));
        exit;
    }
    exit;
}

function chkmobile2()
{ //用于修改密码时检测手机号是否存在
    global $member;
    $value = checkstr($_GET['mobile']);
    $rs = $member->mobile_exists($value);
    if (empty($rs)) {
        echo json_encode(array('tips' => "手机号码不存在"));
        exit;
    } else {
        echo json_encode(array('tips' => "手机号码检测通过"));
        exit;
    }
    exit;
}

function getuserid()
{
    $arr['name'] = getrand();
    echo json_encode($arr);
    exit;
}

function getusername()
{
    global $member;
    $value = checkstr($_GET['username']);
    $rs = $member->getum($value, 'real_name');
    if (!empty($rs)) {
        echo json_encode(array('names' => $rs['real_name']));
    } else {
        echo json_encode(array('names' => ''));
    }
    exit;
}

function chkuser()
{
    global $member;
    $value = trim($_GET['userid']);
    $check = preg_match('/select|or|and|SELECT|INSERT|UPDATE|DELETE|insert|script|function|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile/i', $value);
    if ($check) {
        echo json_encode(array('tips' => '用户名不合法，请换一个！'));
        exit;
    }
    $rs = $member->user_exists($value);
    if (empty($rs)) {
        echo json_encode(array('tips' => '可以使用该用户名注册'));
    } else {
        echo json_encode(array('tips' => '该用户名已经被注册'));
    }
    exit;
}

function chktu()
{
    global $member;
    $value = checkstr($_GET['userid']);
    $rs = $member->tu_exists($value);
    if (empty($rs)) {
        echo json_encode(array('tips' => '推荐人不存在或尚未激活'));
    } else {
        echo json_encode(array('tips' => '推荐人检测通过'));
    }
    exit;
}

function help_detail()
{
    global $db, $GLOBALARR, $member;
    $_userid = $_SESSION['userid'];
    $rlid = checkstr(trim($_POST['rlid']));
    $help_type = checkstr(trim($_POST['help_type']));
    //取得用户信息
    $us = $member->getuserinfo($_userid);
    $db->query("select * from ld_remit_list where id=" . $rlid, 2);
    $remit_info = $db->rs;
    $result = array();
    if ($help_type == "give") {
        $result['help_type'] = "give";
        $result['give_help_uname'] = $us['uname'];
        $result['give_help_realname'] = $us['nick_name'];
        $result['give_help_phone'] = $us['phone'];
        $result['give_help_qq'] = $us['rgqq'];
        $result['give_help_weixin'] = $us['rgweixin'];
        //提供帮助人的直接上线
        $ldi = $member->getldpname($remit_info["give_help_id"]);
        $result["give_help_lduname"] = $ldi["uname"];
        $result["give_help_ldphone"] = $ldi["phone"];
        $result["give_help_ldqq"] = $ldi["rgqq"];
        $result["give_help_ldweixin"] = $ldi["rgweixin"];
        $result["give_help_ldrealname"] = $ldi["nick_name"];
        //根据id取得获得帮助记录
        $db->query("select * from ld_get_help where id=" . $remit_info["get_help_id"], 2);
        //取得获得帮助人信息
        $get_help_user = $member->getuserinfo($db->rs["get_help_uid"]);
        $db->query("select * from ld_bank where is_default=1 and uname='" . $get_help_user["uname"] . "'", 2);
        $result["get_help_bankname"] = $db->rs["bankname"];
        $result["get_help_realname"] = $db->rs["customer_name"];
        $result["get_help_nickname"] = $get_help_user['nick_name'];
        $result["get_help_bankno"] = $db->rs["bankno"];
        $result["get_help_bankaddress"] = $db->rs["bankaddress"];
        $result["get_help_phone"] = $get_help_user["phone"];
        $result["get_help_qq"] = $get_help_user["rgqq"];
        $result["get_help_weixin"] = $get_help_user["rgweixin"];
        $result["get_help_uname"] = $get_help_user["uname"];
        //获得帮助人的直接上线
        $lde = $member->getldqname($remit_info["get_help_id"]);
        $result["get_help_lduname"] = $lde["uname"];
        $result["get_help_ldphone"] = $lde["phone"];
        $result["get_help_ldqq"] = $lde["rgqq"];
        $result["get_help_ldweixin"] = $lde["rgweixin"];
        $result["get_help_ldrealname"] = $lde["nick_name"];
    } elseif ($help_type == "get") {
        $result['help_type'] = "get";
        $result['get_help_uname'] = $us['uname'];
        $result['get_help_realname'] = $us['real_name'];
        $result['get_help_nickname'] = $us['nick_name'];
        $result['get_help_phone'] = $us['phone'];
        $result['get_help_qq'] = $us['rgqq'];
        $result['get_help_weixin'] = $us['rgweixin'];
        //获得帮助人的直接上线
        $lde = $member->getldqname($remit_info["get_help_id"]);
        $result["get_help_lduname"] = $lde["uname"];
        $result["get_help_ldphone"] = $lde["phone"];
        $result["get_help_ldqq"] = $lde["rgqq"];
        $result["get_help_ldweixin"] = $lde["rgweixin"];
        $result["get_help_ldrealname"] = $lde["nick_name"];
        //根据id取得提供帮助记录
        $db->query("select * from ld_give_help where id=" . $remit_info["give_help_id"], 2);
        //取得提供帮助人信息
        $give_help_user = $member->getuserinfo($db->rs["uid"]);
        $db->query("select * from ld_bank where is_default=1 and uname='" . $give_help_user["uname"] . "'", 2);
        $result["give_help_bankname"] = $db->rs["bankname"];
        $result["give_help_realname"] = $give_help_user['nick_name'];
        $result["give_help_bankno"] = $db->rs["bankno"];
        $result["give_help_bankaddress"] = $db->rs["bankaddress"];
        $result["give_help_phone"] = $give_help_user["phone"];
        $result["give_help_qq"] = $give_help_user["rgqq"];
        $result["give_help_weixin"] = $give_help_user["rgweixin"];
        $result["give_help_uname"] = $give_help_user["uname"];
        //提供帮助人的直接上线
        $ldi = $member->getldpname($remit_info["give_help_id"]);
        $result["give_help_lduname"] = $ldi["uname"];
        $result["give_help_ldphone"] = $ldi["phone"];
        $result["give_help_ldqq"] = $ldi["rgqq"];
        $result["give_help_ldweixin"] = $ldi["rgweixin"];
        $result["give_help_ldrealname"] = $ldi["nick_name"];

        //根据id取得获得帮助记录
        $db->query("select * from ld_get_help where id=" . $remit_info["get_help_id"], 2);
        //取得提供帮助人信息
        $get_help_user = $member->getuserinfo($db->rs["get_help_uid"]);
        $db->query("select * from ld_bank where is_default=1 and uname='" . $get_help_user["uname"] . "'", 2);
        $result["get_help_bankname"] = $db->rs["bankname"];
        $result["get_help_bankno"] = $db->rs["bankno"];
        $result["get_help_bankaddress"] = $db->rs["bankaddress"];
    }
    echo json_encode($result);
    exit;
}

function give_help_detail()
{
    global $db, $GLOBALARR, $member;
    $order_no = checkstr(trim($_POST['order_no']));
    $db->query("select * from ld_give_help where give_help_no = '" . $order_no . "'", 2);
    $give_help_info = $db->rs;
    if (!empty($give_help_info)) {
        $member_info = $member->getum($give_help_info['uname']);
        $result['real_name'] = $member_info['real_name'];
        $result['nick_name'] = $member_info['nick_name'];
        $result['give_help_uname'] = $give_help_info['uname'];
        $result['give_help_amount'] = $give_help_info['amount'];
        $result['contact_phone'] = $member_info['phone'];
        $result['status'] = 1;
        echo json_encode($result);
    } else {
        echo json_encode(array('mes' => "获取订单信息失败！", 'status' => 0));
    }
    exit;
}

function give_help_dzorders()
{
    global $db, $GLOBALARR, $member;
    $id = checkstr(trim($_POST['id']));
    $db->query("select * from ld_give_help where id = " . $id . "", 2);
    $infos = $db->rs;
    if (!empty($infos['good_ids']) && !empty($infos['good_nums'])) {
        $ids = explode(",", $infos['good_ids']);
        $good_nums = explode(",", $infos['good_nums']);
        foreach ($ids as $key => $v) {
            if ($v == '') {
                continue;
            }
            $db->query("select * from ld_product where id=" . $v, 2);
            $good = $db->rs;
            if (!$good) {
                continue;
            }
            $result['mes'][$key]['productname'] = $good['productname'];
            $result['mes'][$key]['num'] = $good_nums[$key];
        }
        $result['status'] = 1;
        echo json_encode($result);
    } else {
        echo json_encode(array('mes' => "获取订单信息失败！", 'status' => 0));
    }
    exit;
}

function checkvalicode()
{
    $yzm = checkstr(trim($_POST["valicode"]));
    $code = strtolower($_SESSION["code"]);
    if ($code != $yzm) {
        echo json_encode(array('mes' => "验证码错误！", 'status' => 0));
    } else {
        echo json_encode(array('mes' => "验证码正确！", 'status' => 1));
    }
    exit;
}

function getaddress()
{
    global $CoinClient, $member, $db;
    $_userid = $_SESSION['userid'];
    $us = $member->getuserinfo($_userid);
    $name = $us['uname'];
    $json = $CoinClient->getinfo();
    if (!isset($json['version']) || !$json['version']) {
        echo json_encode(array('mes' => "钱包链接失败！", 'status' => 0));
        return;
    }
    $qianbao_addr = $CoinClient->getaddressesbyaccount($name);
    if (!is_array($qianbao_addr)) {
        $qianbao_ad = $CoinClient->getnewaddress($name);
        if (!$qianbao_ad) {
            $this->error('生成钱包地址出错1！');
            echo json_encode(array('mes' => "生成电子钱包地址出错1", 'status' => 0));
        } else {
            $qianbao = $qianbao_ad;
        }
    } else {
        $qianbao = $qianbao_addr[0];
    }

    if (!$qianbao) {
        echo json_encode(array('mes' => "生成电子钱包地址出错2", 'status' => 0));

    }
    $db->query("update ld_user_account set xfb_address='" . $qianbao . "' where id=" . $_userid . "", 4);
    echo json_encode(array('mes' => $qianbao, 'status' => 1));
}

function getaddress_btc()
{
    global $CoinClient_btc, $member, $db;
    $_userid = $_SESSION['userid'];
    $us = $member->getuserinfo($_userid);
    $name = $us['uname'];
    $json = $CoinClient_btc->getinfo();
    if (!isset($json['version']) || !$json['version']) {
        echo json_encode(array('mes' => "钱包链接失败！", 'status' => 0));
        return;
    }
    $qianbao_addr = $CoinClient_btc->getaddressesbyaccount($name);
    if (!is_array($qianbao_addr)) {
        $qianbao_ad = $CoinClient_btc->getnewaddress($name);
        if (!$qianbao_ad) {
            $this->error('生成钱包地址出错1！');
            echo json_encode(array('mes' => "生成电子钱包地址出错1", 'status' => 0));
        } else {
            $qianbao = $qianbao_ad;
        }
    } else {
        $qianbao = $qianbao_addr[0];
    }

    if (!$qianbao) {
        echo json_encode(array('mes' => "生成电子钱包地址出错2", 'status' => 0));

    }
    $db->query("update ld_user_account set btc_address='" . $qianbao . "' where id=" . $_userid . "", 4);
    echo json_encode(array('mes' => $qianbao, 'status' => 1));
}

function getaddress_ltc()
{
    global $CoinClient_ltc, $member, $db;
    $_userid = $_SESSION['userid'];
    $us = $member->getuserinfo($_userid);
    $name = $us['uname'];
    $json = $CoinClient_ltc->getinfo();
    if (!isset($json['version']) || !$json['version']) {
        echo json_encode(array('mes' => "钱包链接失败！", 'status' => 0));
        return;
    }
    $qianbao_addr = $CoinClient_ltc->getaddressesbyaccount($name);
    if (!is_array($qianbao_addr)) {
        $qianbao_ad = $CoinClient_ltc->getnewaddress($name);
        if (!$qianbao_ad) {
            $this->error('生成钱包地址出错1！');
            echo json_encode(array('mes' => "生成电子钱包地址出错1", 'status' => 0));
        } else {
            $qianbao = $qianbao_ad;
        }
    } else {
        $qianbao = $qianbao_addr[0];
    }

    if (!$qianbao) {
        echo json_encode(array('mes' => "生成电子钱包地址出错2", 'status' => 0));

    }
    $db->query("update ld_user_account set ltc_address='" . $qianbao . "' where id=" . $_userid . "", 4);
    echo json_encode(array('mes' => $qianbao, 'status' => 1));
}

//语言选择
function choice_lange()
{
    $lange = checkstr($_GET['lange']);
    $_SESSION['lange'] = $lange;
    echo json_encode(array('status' => 1));
    exit;

}

function checkphone()
{
    global $member, $db;
    $phone = checkstr($_GET['phones']);
    if (!preg_match("/^1[34578]{1}\d{9}$/", $phone)) {
        echo json_encode(array('status' => 0, 'res' => 'Mobile phone number is not correct'));
        exit;
    }
    $db->query("select * from ld_user_info where phone='" . $phone . "' limit 1", 2);
    $res = $db->rs;
    if ($res) {
        echo json_encode(array('status' => 0, 'res' => '手机号码已存在!'));
        exit;
    }
    echo json_encode(array('status' => 1, 'res' => '手机号码可以修改!'));
    exit;

}

//修改手机号
function changephone()
{
    global $member, $db;
    $code = checkstr($_GET['pcode']);
    $phone = checkstr($_GET['phones']);
    if (empty($code)) {
        echo json_encode(array('status' => 0, 'res' => '请输入验证码！'));
        exit;
    }
    if ($code != $_SESSION['mobile_code']) {
        echo json_encode(array('status' => 0, 'res' => '验证码输入不正确！'));
        exit;
    }
    if (!preg_match("/^1[34578]{1}\d{9}$/", $phone)) {
        echo json_encode(array('status' => 0, 'res' => '手机号码格式不正确'));
        exit;
    }
    $db->query("select * from ld_user_info where phone='" . $phone . "' limit 1", 2);
    $res = $db->rs;
    if ($res) {
        echo json_encode(array('status' => 0, 'res' => '手机号码已存在!'));
        exit;
    }
    $_userid = $_SESSION['userid'];
    //验证码通过
    $db->query("update ld_user_info set phone='" . $phone . "' where id='" . $_userid . "'", 4);
    echo json_encode(array('status' => 1, 'res' => '手机号码修改成功!'));
    exit;

}

function chuchang()
{
    global $member, $db, $GLOBALARR;
    $_userid = $_SESSION['userid'];
    $id = intval(checkstr($_GET['id']));
    if ($id < 1) {
        echo json_encode(array('status' => 0, 'tips' => '消费订单号有误!'));
        return;
    }
    $db->query("select * from ld_give_help where id=" . $id . " and uid=" . $_userid . "", 2);
    $give_info = $db->rs;
    if (!$give_info) {
        echo json_encode(array('status' => 0, 'tips' => '不存在该订单!'));
        return;
    } else {
        if ($give_info['xf_type'] == 1) {
            echo json_encode(array('status' => 0, 'tips' => '您的消费方式有误!'));
            return;
        }
        if ($give_info['status'] == 1 && $give_info['had_shouyi'] == 1) {
            echo json_encode(array('status' => 0, 'tips' => '您已经出场过了!'));
            return;
        }
        if (time() - $give_info['give_help_time'] < $GLOBALARR['perdays'] * 24 * 3600) {
            echo json_encode(array('status' => 0, 'tips' => '您的消费订单还未解冻!'));
            return;
        } else {
            //手动出场发利息
            $bjin = $give_info['amount'];
            $lixi = $give_info['benifit_amount'];
            $tot = $bjin + $lixi;
            $newlixi = $lixi * $GLOBALARR['duib_jt'] / 100;
            $fxjifen = $lixi * $GLOBALARR['duifx_jt'] / 100;
            //增加发展基金7/25
            $fzjijin = $lixi * $GLOBALARR['duifz_jt'] / 100;

            try {
                $db->begintransaction();
                $db->lspre("update ld_user_account set total_prize=total_prize+:t1 where id=:t0", 4, array(array(':t0', ':t1'), array($_userid, $tot)));
                //增加利息
                writeaccount(array($_userid, "0", 11, time(), 31, $newlixi, '利息' . $lixi . '的' . $GLOBALARR['duib_jt'] . '%手动转入静态收益-排单编号|' . $give_info['give_help_no']));
                //增加共享积分 是否出局 7/18/gao
                if ($give_info['is_out'] == 0) {
                    writeaccount(array($_userid, "0", 21, time(), 201, $bjin, '排单赠送积分收益手动转入复消赠送积分-编号|' . $give_info['give_help_no']));
                }
                //增加积分
                writeaccount(array($_userid, "0", 12, time(), 35, $fxjifen, '利息' . $lixi . '的' . $GLOBALARR['duifx_jt'] . '%手动转入商城积分钱包-排单编号|' . $give_info['give_help_no']));
                //增加发展基金
                writeaccount(array($_userid, "0", 22, time(), 220, $fzjijin, '利息' . $lixi . '的' . $GLOBALARR['duifz_jt'] . '%手动转入发展基金-排单编号|' . $give_info['give_help_no']));

                //状态更新
                $db->query("update ld_give_help set status=1,flx_time=" . time() . ",had_shouyi=1 where id=" . $give_info['id'], 4);
                //prize_list 表也更新
                $db->sitedbexec("update ld_prize_list set prize_status=1 where help_id=" . $give_info['id'] . " and prize_option=51 and prize_status=0  and uid=" . $_userid . "");
                $db->committransaction();    //关闭自动提交
            } catch (PDOException $e) {
                $db->rollbacktransaction();
                echo json_encode(array('status' => 0, 'tips' => '出错了!'));
                return;
            }

            echo json_encode(array('status' => 1, 'tips' => '手动出场成功!'));
            return;

        }
    }

}

function tiben()
{
    global $member, $db, $GLOBALARR;
    $_userid = $_SESSION['userid'];
    $id = intval($_GET['id']);
    if (empty($_userid)) {
        echo json_encode(array('status' => 1, 'tips' => '请先登录!'));
        return;
    }
    if (empty($id)) {
        echo json_encode(array('status' => 1, 'tips' => '不存在!'));
        return;
    }
    $db->query("select * from ld_lock_log where uid=" . $_userid . " and id=" . $id, 2);
    $give = $db->rs;
    if (!$give) {
        echo json_encode(array('status' => 1, 'tips' => '没有查询到!'));
        return;
    }
    if ($give['status'] != 0) {
        echo json_encode(array('status' => 1, 'tips' => '已经结束!'));
        return;
    }
    if ($give['pid'] == 6) {
        echo json_encode(array('status' => 1, 'tips' => '该套餐未开通解锁功能'));
        return;
    }
    try {
        $db->begintransaction();
        //直接退本金
        if ($give['type'] == 1) {
        	$update_sql = "update ld_user_account set cash_purse = cash_purse + ".$give['nums'].",freeze_benjin = freeze_benjin - ".$give['nums']." where id = ".$_userid;
			$db->sitedbexec($update_sql);
        }
        if ($give['type'] == 2) {
			$update_sql = "update ld_user_account set lixi_crash = lixi_crash + ".$give['nums'].",freeze_lixi = freeze_lixi - ".$give['nums']." where id = ".$_userid;
			$db->sitedbexec($update_sql);
        }
        if ($give['type'] == 3) {
			$update_sql = "update ld_user_account set keyong_ldprize = keyong_ldprize + ".$give['nums'].",freeze_ldj = freeze_ldj - ".$give['nums']." where id = ".$_userid;
			$db->sitedbexec($update_sql);
        }
        $db->sitedbexec("update ld_lock_log set status=2 where id=" . $give['id']);
        $db->committransaction();    //关闭自动提交
    } catch (PDOException $e) {
        $db->rollbacktransaction();
        echo json_encode(array('status' => 0, 'tips' => '出错了!'));
        return;
    }
    echo json_encode(array('status' => 1, 'tips' => '解锁成功!'));
    return;


}

function deleqd()
{
    global $member, $db, $GLOBALARR;
    $_userid = $_SESSION['userid'];
    if (!$_userid) {
        echo json_encode(array('status' => 0, 'tips' => '你已超时登录，请重新登录!'));
        return;
    }
    $user = $member->getuserinfo($_userid);
    $qdid = intval($_GET['qbid']);
    $pwd = checkstr($_GET['pwd']);
    if (empty($qdid)) {
        echo json_encode(array('status' => 0, 'tips' => '请选择要删除的钱包地址!'));
        return;
    }
    if (empty($pwd)) {
        echo json_encode(array('status' => 0, 'tips' => '密码不能为空!'));
        return;
    }
    if (getpwd($pwd) != $user['rgpwd2']) {
        echo json_encode(array('status' => 0, 'tips' => '密码不正确!'));
        return;
    }
    $ddddd = qianbao_delete($_userid, $qdid);
    echo json_encode(array('status' => 1, 'tips' => '删除成功!'));
    return;

}

?>
